

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>kospeech.data.data_loader &mdash; KoSpeech 0.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> KoSpeech
          

          
          </a>

          
            
            
              <div class="version">
                0.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">NOTES</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../notes/intro.html">Intro</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../notes/Preparation.html">Preparation before Training</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../notes/opts.html">Options</a></li>
</ul>
<p class="caption"><span class="caption-text">ARCHITECTURE</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Seq2seq.html">Seq2seq</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Transformer.html">Transformer</a></li>
</ul>
<p class="caption"><span class="caption-text">PACKAGE REFERENCE</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Checkpoint.html">Checkpoint</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Data.html">Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Decode.html">Decode</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Evaluator.html">Evaluator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Optim.html">Optim</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Trainer.html">Trainer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Etc.html">Etc</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">KoSpeech</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>kospeech.data.data_loader</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for kospeech.data.data_loader</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="k">import</span> <span class="n">Dataset</span>
<span class="kn">from</span> <span class="nn">kospeech.data.label_loader</span> <span class="k">import</span> <span class="n">load_targets</span>
<span class="kn">from</span> <span class="nn">kospeech.data.audio.parser</span> <span class="k">import</span> <span class="n">SpectrogramParser</span>
<span class="kn">from</span> <span class="nn">kospeech.utils</span> <span class="k">import</span> <span class="n">logger</span><span class="p">,</span> <span class="n">PAD_token</span><span class="p">,</span> <span class="n">SOS_token</span><span class="p">,</span> <span class="n">EOS_token</span>


<div class="viewcode-block" id="SpectrogramDataset"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.SpectrogramDataset">[docs]</a><span class="k">class</span> <span class="nc">SpectrogramDataset</span><span class="p">(</span><span class="n">Dataset</span><span class="p">,</span> <span class="n">SpectrogramParser</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Dataset for feature &amp; transcript matching</span>

<span class="sd">    Args:</span>
<span class="sd">        audio_paths (list): set of audio path</span>
<span class="sd">        script_paths (list): set of script paths</span>
<span class="sd">        sos_id (int): identification of &lt;start of sequence&gt;</span>
<span class="sd">        eos_id (int): identification of &lt;end of sequence&gt;</span>
<span class="sd">        target_dict (dict): dictionary of filename and labels</span>
<span class="sd">        spec_augment (bool): flag indication whether to use spec-augmentation or not (default: True)</span>
<span class="sd">        noise_augment (bool): flag indication whether to use noise-augmentation or not (default: True)</span>
<span class="sd">        opt (ArgumentParser): set of arguments</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">audio_paths</span><span class="p">,</span> <span class="n">script_paths</span><span class="p">,</span> <span class="n">sos_id</span><span class="p">,</span> <span class="n">eos_id</span><span class="p">,</span>
                 <span class="n">target_dict</span><span class="p">,</span> <span class="n">opt</span><span class="p">,</span> <span class="n">spec_augment</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">noise_augment</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">dataset_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">noiseset_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">noise_level</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">SpectrogramDataset</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">feature_extract_by</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">feature_extract_by</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">sample_rate</span><span class="p">,</span>
                                                 <span class="n">n_mels</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">n_mels</span><span class="p">,</span>
                                                 <span class="n">frame_length</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">frame_length</span><span class="p">,</span> <span class="n">frame_shift</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">frame_shift</span><span class="p">,</span>
                                                 <span class="n">del_silence</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">del_silence</span><span class="p">,</span> <span class="n">input_reverse</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">input_reverse</span><span class="p">,</span>
                                                 <span class="n">normalize</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">normalize</span><span class="p">,</span> <span class="n">target_dict</span><span class="o">=</span><span class="n">target_dict</span><span class="p">,</span>
                                                 <span class="n">time_mask_para</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">time_mask_para</span><span class="p">,</span> <span class="n">freq_mask_para</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">freq_mask_para</span><span class="p">,</span>
                                                 <span class="n">time_mask_num</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">time_mask_num</span><span class="p">,</span> <span class="n">freq_mask_num</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">freq_mask_num</span><span class="p">,</span>
                                                 <span class="n">sos_id</span><span class="o">=</span><span class="n">sos_id</span><span class="p">,</span> <span class="n">eos_id</span><span class="o">=</span><span class="n">eos_id</span><span class="p">,</span> <span class="n">dataset_path</span><span class="o">=</span><span class="n">dataset_path</span><span class="p">,</span>
                                                 <span class="n">noiseset_size</span><span class="o">=</span><span class="n">noiseset_size</span><span class="p">,</span> <span class="n">noise_level</span><span class="o">=</span><span class="n">noise_level</span><span class="p">,</span>
                                                 <span class="n">noise_augment</span><span class="o">=</span><span class="n">noise_augment</span><span class="p">,</span> <span class="n">transform_method</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">transform_method</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">audio_paths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">script_paths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">VANILLA</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">augmentation</span><span class="p">(</span><span class="n">spec_augment</span><span class="p">,</span> <span class="n">noise_augment</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shuffle</span><span class="p">()</span>

<div class="viewcode-block" id="SpectrogramDataset.get_item"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.SpectrogramDataset.get_item">[docs]</a>    <span class="k">def</span> <span class="nf">get_item</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; get feature &amp; transcript &quot;&quot;&quot;</span>
        <span class="n">transcript</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_transcript</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>
        <span class="n">feature_vector</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_audio</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>

        <span class="k">if</span> <span class="n">feature_vector</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">feature_vector</span><span class="p">,</span> <span class="n">transcript</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">feature_vector</span><span class="p">,</span> <span class="n">transcript</span></div>

<div class="viewcode-block" id="SpectrogramDataset.parse_transcript"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.SpectrogramDataset.parse_transcript">[docs]</a>    <span class="k">def</span> <span class="nf">parse_transcript</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script_path</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Parses scripts @Override &quot;&quot;&quot;</span>
        <span class="n">transcripts</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

        <span class="n">key</span> <span class="o">=</span> <span class="n">script_path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">transcript</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

        <span class="n">tokens</span> <span class="o">=</span> <span class="n">transcript</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>

        <span class="n">transcripts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sos_id</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">tokens</span><span class="p">:</span>
            <span class="n">transcripts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">token</span><span class="p">))</span>
        <span class="n">transcripts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eos_id</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">transcripts</span></div>

<div class="viewcode-block" id="SpectrogramDataset.augmentation"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.SpectrogramDataset.augmentation">[docs]</a>    <span class="k">def</span> <span class="nf">augmentation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spec_augment</span><span class="p">,</span> <span class="n">noise_augment</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Spec &amp; Noise Augmentation &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">spec_augment</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Applying Spec Augmentation...&quot;</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_size</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">SPEC_AUGMENT</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>

        <span class="k">if</span> <span class="n">noise_augment</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Applying Noise Augmentation...&quot;</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_size</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">NOISE_INJECTION</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span></div>

<div class="viewcode-block" id="SpectrogramDataset.shuffle"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.SpectrogramDataset.shuffle">[docs]</a>    <span class="k">def</span> <span class="nf">shuffle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Shuffle dataset &quot;&quot;&quot;</span>
        <span class="n">tmp</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span><span class="p">))</span>
        <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">script_paths</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">augment_methods</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">tmp</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">audio_paths</span><span class="p">)</span></div>


<div class="viewcode-block" id="AudioDataLoader"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.AudioDataLoader">[docs]</a><span class="k">class</span> <span class="nc">AudioDataLoader</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Audio Data Loader</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset (kodpeech.data.data_loader.SpectrogramDataset): dataset for feature &amp; transcript matching</span>
<span class="sd">        queue (Queue.queue): queue for threading</span>
<span class="sd">        batch_size (int): size of batch</span>
<span class="sd">        thread_id (int): identification of thread</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset</span><span class="p">,</span> <span class="n">queue</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">thread_id</span><span class="p">):</span>
        <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">collate_fn</span> <span class="o">=</span> <span class="n">_collate_fn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">queue</span> <span class="o">=</span> <span class="n">queue</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">batch_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_count</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">thread_id</span> <span class="o">=</span> <span class="n">thread_id</span>

    <span class="k">def</span> <span class="nf">create_empty_batch</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">seqs</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="n">targets</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">long</span><span class="p">)</span>

        <span class="n">seq_lengths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">target_lengths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">seqs</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">seq_lengths</span><span class="p">,</span> <span class="n">target_lengths</span>

<div class="viewcode-block" id="AudioDataLoader.run"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.AudioDataLoader.run">[docs]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Load data from MelSpectrogramDataset &quot;&quot;&quot;</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;loader </span><span class="si">%d</span><span class="s1"> start&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">thread_id</span><span class="p">)</span>

        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
            <span class="n">items</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

            <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_count</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="n">spectrogram</span><span class="p">,</span> <span class="n">transcript</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">get_item</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>

                <span class="k">if</span> <span class="n">spectrogram</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">items</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">spectrogram</span><span class="p">,</span> <span class="n">transcript</span><span class="p">))</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">items</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_empty_batch</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">queue</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">batch</span><span class="p">)</span>
                <span class="k">break</span>

            <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">collate_fn</span><span class="p">(</span><span class="n">items</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">queue</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">batch</span><span class="p">)</span>

        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;loader </span><span class="si">%d</span><span class="s1"> stop&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">thread_id</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_count</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span><span class="p">)</span></div>


<span class="k">def</span> <span class="nf">_collate_fn</span><span class="p">(</span><span class="n">batch</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; functions that pad to the maximum sequence length &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">seq_length_</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">target_length_</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

    <span class="c1"># sort by sequence length for rnn.pack_padded_sequence()</span>
    <span class="n">batch</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">batch</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">sample</span><span class="p">:</span> <span class="n">sample</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">seq_lengths</span> <span class="o">=</span> <span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">batch</span><span class="p">]</span>
    <span class="n">target_lengths</span> <span class="o">=</span> <span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">batch</span><span class="p">]</span>

    <span class="n">max_seq_sample</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">batch</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">seq_length_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">max_target_sample</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">batch</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">target_length_</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>

    <span class="n">max_seq_size</span> <span class="o">=</span> <span class="n">max_seq_sample</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">max_target_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">max_target_sample</span><span class="p">)</span>

    <span class="n">feat_size</span> <span class="o">=</span> <span class="n">max_seq_sample</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">batch_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">batch</span><span class="p">)</span>

    <span class="n">seqs</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">max_seq_size</span><span class="p">,</span> <span class="n">feat_size</span><span class="p">)</span>

    <span class="n">targets</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">max_target_size</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">long</span><span class="p">)</span>
    <span class="n">targets</span><span class="o">.</span><span class="n">fill_</span><span class="p">(</span><span class="n">PAD_token</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">batch_size</span><span class="p">):</span>
        <span class="n">sample</span> <span class="o">=</span> <span class="n">batch</span><span class="p">[</span><span class="n">x</span><span class="p">]</span>
        <span class="n">tensor</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">target</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">seq_length</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">seqs</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">narrow</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">seq_length</span><span class="p">)</span><span class="o">.</span><span class="n">copy_</span><span class="p">(</span><span class="n">tensor</span><span class="p">)</span>
        <span class="n">targets</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">narrow</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">target</span><span class="p">))</span><span class="o">.</span><span class="n">copy_</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">LongTensor</span><span class="p">(</span><span class="n">target</span><span class="p">))</span>

    <span class="n">seq_lengths</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">IntTensor</span><span class="p">(</span><span class="n">seq_lengths</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">seqs</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">seq_lengths</span><span class="p">,</span> <span class="n">target_lengths</span>


<div class="viewcode-block" id="MultiDataLoader"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.MultiDataLoader">[docs]</a><span class="k">class</span> <span class="nc">MultiDataLoader</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Multi Data Loader using Threads.</span>

<span class="sd">    Args:</span>
<span class="sd">        dataset_list (list): list of MelSpectrogramDataset</span>
<span class="sd">        queue (Queue.queue): queue for threading</span>
<span class="sd">        batch_size (int): size of batch</span>
<span class="sd">        num_workers (int): the number of cpu cores used</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataset_list</span><span class="p">,</span> <span class="n">queue</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">num_workers</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span> <span class="o">=</span> <span class="n">dataset_list</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">queue</span> <span class="o">=</span> <span class="n">queue</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">batch_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span> <span class="o">=</span> <span class="n">num_workers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">loader</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">loader</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">AudioDataLoader</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">queue</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">idx</span><span class="p">))</span>

<div class="viewcode-block" id="MultiDataLoader.start"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.MultiDataLoader.start">[docs]</a>    <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Run threads &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">loader</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span><span class="o">.</span><span class="n">start</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiDataLoader.join"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.MultiDataLoader.join">[docs]</a>    <span class="k">def</span> <span class="nf">join</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Wait for the other threads &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">loader</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span><span class="o">.</span><span class="n">join</span><span class="p">()</span></div></div>


<div class="viewcode-block" id="split_dataset"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.split_dataset">[docs]</a><span class="k">def</span> <span class="nf">split_dataset</span><span class="p">(</span><span class="n">opt</span><span class="p">,</span> <span class="n">audio_paths</span><span class="p">,</span> <span class="n">script_paths</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    split into training set and validation set.</span>

<span class="sd">    Args:</span>
<span class="sd">        opt (ArgumentParser): set of options</span>
<span class="sd">        audio_paths (list): set of audio path</span>
<span class="sd">        script_paths (list): set of script path</span>

<span class="sd">    Returns: train_batch_num, train_dataset_list, valid_dataset</span>
<span class="sd">        - **train_time_step** (int): number of time step for training</span>
<span class="sd">        - **trainset_list** (list): list of training dataset</span>
<span class="sd">        - **validset** (data_loader.MelSpectrogramDataset): validation dataset</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">target_dict</span> <span class="o">=</span> <span class="n">load_targets</span><span class="p">(</span><span class="n">script_paths</span><span class="p">)</span>

    <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;split dataset start !!&quot;</span><span class="p">)</span>
    <span class="n">trainset_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">train_num</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">audio_paths</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">opt</span><span class="o">.</span><span class="n">valid_ratio</span><span class="p">))</span>
    <span class="n">total_time_step</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">audio_paths</span><span class="p">)</span> <span class="o">/</span> <span class="n">opt</span><span class="o">.</span><span class="n">batch_size</span><span class="p">)</span>
    <span class="n">valid_time_step</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">total_time_step</span> <span class="o">*</span> <span class="n">opt</span><span class="o">.</span><span class="n">valid_ratio</span><span class="p">)</span>
    <span class="n">train_time_step</span> <span class="o">=</span> <span class="n">total_time_step</span> <span class="o">-</span> <span class="n">valid_time_step</span>
    <span class="n">base_time_step</span> <span class="o">=</span> <span class="n">train_time_step</span>

    <span class="k">if</span> <span class="n">opt</span><span class="o">.</span><span class="n">spec_augment</span><span class="p">:</span>
        <span class="n">train_time_step</span> <span class="o">+=</span> <span class="n">base_time_step</span>

    <span class="k">if</span> <span class="n">opt</span><span class="o">.</span><span class="n">noise_augment</span><span class="p">:</span>
        <span class="n">train_time_step</span> <span class="o">+=</span> <span class="n">base_time_step</span>

    <span class="n">train_num_per_worker</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">train_num</span> <span class="o">/</span> <span class="n">opt</span><span class="o">.</span><span class="n">num_workers</span><span class="p">)</span>

    <span class="c1"># audio_paths &amp; script_paths shuffled in the same order</span>
    <span class="c1"># for seperating train &amp; validation</span>
    <span class="n">tmp</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">audio_paths</span><span class="p">,</span> <span class="n">script_paths</span><span class="p">))</span>
    <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
    <span class="n">audio_paths</span><span class="p">,</span> <span class="n">script_paths</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">tmp</span><span class="p">)</span>

    <span class="c1"># seperating the train dataset by the number of workers</span>
    <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">opt</span><span class="o">.</span><span class="n">num_workers</span><span class="p">):</span>
        <span class="n">train_begin_idx</span> <span class="o">=</span> <span class="n">train_num_per_worker</span> <span class="o">*</span> <span class="n">idx</span>
        <span class="n">train_end_idx</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">train_num_per_worker</span> <span class="o">*</span> <span class="p">(</span><span class="n">idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">train_num</span><span class="p">)</span>

        <span class="n">trainset_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
            <span class="n">SpectrogramDataset</span><span class="p">(</span>
                <span class="n">audio_paths</span><span class="p">[</span><span class="n">train_begin_idx</span><span class="p">:</span><span class="n">train_end_idx</span><span class="p">],</span>
                <span class="n">script_paths</span><span class="p">[</span><span class="n">train_begin_idx</span><span class="p">:</span><span class="n">train_end_idx</span><span class="p">],</span>
                <span class="n">SOS_token</span><span class="p">,</span> <span class="n">EOS_token</span><span class="p">,</span>
                <span class="n">target_dict</span><span class="o">=</span><span class="n">target_dict</span><span class="p">,</span>
                <span class="n">opt</span><span class="o">=</span><span class="n">opt</span><span class="p">,</span>
                <span class="n">spec_augment</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">spec_augment</span><span class="p">,</span>
                <span class="n">noise_augment</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">noise_augment</span><span class="p">,</span>
                <span class="n">dataset_path</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">dataset_path</span><span class="p">,</span>
                <span class="n">noiseset_size</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">noiseset_size</span><span class="p">,</span>
                <span class="n">noise_level</span><span class="o">=</span><span class="n">opt</span><span class="o">.</span><span class="n">noise_level</span>
            <span class="p">)</span>
        <span class="p">)</span>

    <span class="n">validset</span> <span class="o">=</span> <span class="n">SpectrogramDataset</span><span class="p">(</span>
        <span class="n">audio_paths</span><span class="o">=</span><span class="n">audio_paths</span><span class="p">[</span><span class="n">train_num</span><span class="p">:],</span>
        <span class="n">script_paths</span><span class="o">=</span><span class="n">script_paths</span><span class="p">[</span><span class="n">train_num</span><span class="p">:],</span>
        <span class="n">sos_id</span><span class="o">=</span><span class="n">SOS_token</span><span class="p">,</span> <span class="n">eos_id</span><span class="o">=</span><span class="n">EOS_token</span><span class="p">,</span>
        <span class="n">target_dict</span><span class="o">=</span><span class="n">target_dict</span><span class="p">,</span>
        <span class="n">opt</span><span class="o">=</span><span class="n">opt</span><span class="p">,</span>
        <span class="n">spec_augment</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">noise_augment</span><span class="o">=</span><span class="kc">False</span>
    <span class="p">)</span>

    <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;split dataset complete !!&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">train_time_step</span><span class="p">,</span> <span class="n">trainset_list</span><span class="p">,</span> <span class="n">validset</span></div>


<div class="viewcode-block" id="load_data_list"><a class="viewcode-back" href="../../../Data.html#kospeech.data.data_loader.load_data_list">[docs]</a><span class="k">def</span> <span class="nf">load_data_list</span><span class="p">(</span><span class="n">data_list_path</span><span class="p">,</span> <span class="n">dataset_path</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Provides set of audio path &amp; label path</span>

<span class="sd">    Args:</span>
<span class="sd">        data_list_path (str): csv file with training or test data list path.</span>
<span class="sd">        dataset_path (str): dataset path.</span>

<span class="sd">    Returns: audio_paths, script_paths</span>
<span class="sd">        - **audio_paths** (list): set of audio path</span>
<span class="sd">        - **script_paths** (list): set of label path</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">data_list</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="n">data_list_path</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">delimiter</span><span class="o">=</span><span class="s2">&quot;,&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;cp949&quot;</span><span class="p">)</span>
    <span class="n">audio_paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">dataset_path</span> <span class="o">+</span> <span class="n">data_list</span><span class="p">[</span><span class="s2">&quot;audio&quot;</span><span class="p">])</span>
    <span class="n">script_paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">dataset_path</span> <span class="o">+</span> <span class="n">data_list</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">audio_paths</span><span class="p">,</span> <span class="n">script_paths</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Soohwan Kim

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>